<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title><s:text name="context.title"/></title>
<%@ include file="/common/meta.jsp"%>
<script type="text/javascript" src="${ctx}/js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="${ctx}/js/jquery-ui-1.8.22.custom.min.js"></script>
<script type="text/javascript"> 
$(function(){
	// Dialog
	$('#dialog').dialog({
		autoOpen: false,
		width: 600,
		buttons: {
			"提交": function() {
				$.post("time-control!save?d="+new Date(),{timeId:$("#timeId").val(),startDate:$("#startDate").val(),endDate:$("#endDate").val(),authId:$("#authId").val()},function(data){
					if(data != ''){
						alert(data);
					}else{
						window.location.reload();
					}
					});
				$(this).dialog("close");
			},
			"取消": function() {
				clean();
				
				$(this).dialog("close");
			}
		}
	});
 
 
});

function clean(){
	$("#timeId").val("");
	$("#authId").val("");
	$("#startDate").val("");
	$("#endDate").val("");
}

function _getDate(id,aid){
	$("#timeId").val(id);
	$("#authId").val(aid);
	$("#startDate").val($("#start-" + id).val());
	$("#endDate").val($("#end-" + id).val());
	$('#dialog').dialog('open');
}

function setEffective(id,obj){
	var f = 0;
	if(obj.checked){
		f = 1;
	}
		$.post("time-control!setEffective?d="+new Date(),{authId:id,used:f},function(data){
			if(data != ''){
				alert(data);
			}		
			});
}
</script>

</head>
<body>
<br/>
<p align="center"><s:actionmessage theme="mytheme" cssClass="actionMessage"/></p>



<form id="mainForm" action="time-control.action" method="post">
<h1 class="title01"><img src="${ctx}/images/02_15.gif" width="45" height="42" class="fl"/>时间控制 </h1>
<s:if test="authorities != null && authorities.size() != 0">
<s:iterator value="authorities" var="v">
<fieldset class="fs_ys">
		<legend>${v.name }  生效<input type="checkbox" name="used" onclick="$(this).next('.edit').toggle();setEffective('${v.id}',this)"  value="1" <s:if test="#v.effective == 1">checked="checked"</s:if>/>  <span title="${v.id }"  style="cursor: pointer;<s:if test="#v.effective != 1">display: none;</s:if>" onclick="_getDate('','${v.id }')" class=" edit blue">添加时间</span></legend>
		<table id="contentTable" class="table_ys tableColor">
		<s:iterator value="#v.timeAuthority" var="j">
			<input type="hidden" id="start-${j.id }" value="<s:date format="yyyy-MM-dd" name="#j.startDate"/>"/>
			<input type="hidden" id="end-${j.id }" value="<s:date format="yyyy-MM-dd" name="#j.endDate"/>"/>
			<input type="hidden" id="autId-${j.id }" value="${v.id }"/>
			<tr>
				<td><p><s:date format="yyyy-MM-dd" name="#j.startDate"/> ~ <s:date format="yyyy-MM-dd" name="#j.endDate"/> <span <s:if test="#v.effective != 1">style="display: none;"</s:if> class="edit"> <a class="ui-state-default ui-corner-al" style="padding:3px 10px;text-decoration:none;" title="${j.id }" class="" href="javascript:_getDate('${j.id }','${v.id }')">修改</a>、<a class="ui-state-default ui-corner-al" style="padding:3px 10px;text-decoration:none;" href="time-control!del?timeId=${j.id }" onclick="return confirm('确定删除？')">删除</a></span></p>&nbsp;</td>
			</tr>
		</s:iterator>
		</table>			
</fieldset>
</s:iterator>
</s:if>
</form>
<div id="dialog" title="设置时间">
<input type="hidden" id="timeId"/>
<input type="hidden" id="authId"/>
          <p>开始时间：<input type="text" name="startDate" id="startDate"  onfocus="var inputDateEnd=$dp.$('endDate');WdatePicker({onpicked:function(){inputDateEnd.focus();},maxDate:'#F{$dp.$D(\'endDate\')}'})" class="Wdate"/>
          结束时间：<input type="text" name="endDate" id="endDate"  onfocus="WdatePicker({minDate:'#F{$dp.$D(\'startDate\')}'})" class="Wdate"/>          </p>
</div>
</body>

</html>